<%@page import="java.sql.ResultSet" import="java.sql.Statement" import="java.sql.Connection" import="connection.DBConnection"%>
<%@ page import="java.util.*" language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@page import="java.text.SimpleDateFormat" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Receipts Voucher</title>

<script language="javascript" type="text/javascript">

function checkDate()
{
	var c1;
	
  	var datevalid=/^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
  		
        c1= document.f14.rdate.value;

        if(c1.length==0)
        {
        	alert("Enter Date");
            return false;
      	 }
        if(!c1.match(datevalid))
        {
            alert("Please Enter Date in DD/MM/YYYY Format");
            document.f14.rdate.value="";
            document.f14.rdate.focus();
            
	         return false;
    	 }
        else
        {
        	dateval=c1.match(datevalid);
        }
        
        var dtYear = dateval[1];        
        dtMonth = dateval[3];
        dtDay=  dateval[5];

     if (dtMonth < 1 || dtMonth > 12) 
        return false;
     else if (dtDay < 1 || dtDay> 31) 
       return false;
     else if ((dtMonth==4 || dtMonth==6 || dtMonth==9 || dtMonth==11) && dtDay ==31) 
       return false;
     else if (dtMonth == 2){ 
       var isleap = (dtYear % 4 == 0 && (dtYear % 100 != 0 || dtYear % 400 == 0));
       if (dtDay> 29 || (dtDay ==29 && !isleap)) 
      	 
      	 alert("Date format is not correct");
       document.f14.rdate.value="";
       document.f14.rdate.focus();
              return false;
        
        return true;
}
</script>
<%--
<script language="javascript" type="text/javascript">
function SelectName()
{
	 var cid = raccount.options[raccount.selectedIndex].value;
	 var cnm = raccount.options[raccount.selectedIndex].text;
	 
	 document.getElementById("raccount").value = cid;
	 document.getElementById("raccountcode1").value = cnm;
}

</script>
--%>

<script language="javascript" type="text/javascript">

 function addfields() 
 {    
        var text = '<div><tr><td><input type=text name="raccount2" id="raccount2" ></td></tr></div>',
        newtext = document.getElementById('newtextDiv');
        newtext.contentWindow.document.body.innerHTML = text;    
        
        var text2 = '<div><tr><td><input type=text name="ramountt2" id="ramountt2" ></td></tr></div>',
        newtext2 = document.getElementById('newtext2Div');
        newtext2.contentWindow.document.body.innerHTML = text2;    
 }

 </script> 
 
 <script language="javascript" type="text/javascript">
 	function addRow(tableID)
	{
		var table=document.getElementById(tableID); //table id
		var rowCount=table.rows.length;  //row count of table
		var row=table.insertRow(rowCount-2); 
		var colCount=table.rows[0].cells.length; // column count
		
		for(var i=0;i<colCount;i++)
		{
			var newcell=row.insertCell(i);
			newcell.innerHTML=table.rows[0].cells[i].innerHTML;
			
		//	newcell.childNodes[0].value="";
		//	newcell.childNodes[0].selectedIndex=0;
			
			switch(newcell.childNodes[0].type)
			{
				case"text":newcell.childNodes[0].value="";
					break;
				case"select-one":newcell.childNodes[0].selectedIndex=0;
					break;
				case"text2":newcell.childNodes[0].value="";
					break;
				case"input":newcell.childNodes[0].selectIndex=0;
			}
		}

	}
 </script>
  
</head>
<body>

<form name="f14" action="ReceiptsVoucherServlet" ONSUBMIT="return checkDate()">
<center> <h2><b>Receipts Voucher</b></h2></center>

<table border=0 align=center >

<tr>
	<td> Name of the Bank </td>
	<!--  <td> <input type="text" name="rbankname"> </td> -->
	
			<!--  rbankname --> 
	
		<%-- <%  for(int i=0; i<li2.size();) 
			{	%>
			<select>
				<option> <%= li2.get(i++) %> </option>
			</select>
			
		<%	} %>
		--%>
		
			<%	 DBConnection dbc=new DBConnection();	
				 Connection con=dbc.getNewConnection();
			
				 Statement st = null;
				 ResultSet rs = null;
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select bname from BankMaster"); %>
	<td> 
	  <select name="rbankname">
	  		<option> </option>
       		 <%  while(rs.next()){ %>
            		<option><%= rs.getString(1)%></option>
      
          <% } %>
       </select>
     </td>
  
	 <% }
		catch(Exception e){} %>
		
		<td colspan=2> <a href="BankMaster.jsp"> Create New Bank </a> </td>
				
</tr>

<tr>
		<td> Bank Date </td>
		<td> <input type="text" name="bankdate">
</tr>

<tr>
	<td> Receipt Entry Number </td>
	
			<%	
			 	String code2="RV1";
			
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select MAX(renum) from ReceiptsVoucher2"); %>
       		   
       		 <%  while(rs.next()) 
       		 	 { 
       				String code1=rs.getString(1);
       				
       			    String[] part = code1.split("(?<=\\D)(?=\\d)");
	   		       
	   		       String p0=part[0];		       
	   		       int p1=Integer.parseInt(part[1]);
	   		      
	   		       p1++;
	   		     
	   		   	  code2=p0+""+p1;	   
            	}
       		 		%>
  
	 		<% }
		   catch(Exception e){} %>
	
	<td> <input type="text" name="rentrynumber" value="<%=code2 %>" ></td>
</tr>

<tr>
	<td> date </td>
		<% SimpleDateFormat current = new SimpleDateFormat("dd/MM/yyyy"); %>	
	<td><input type="text" name="rdate" value="<%=current.format(new Date()) %>" /></td>
</tr>

<tr>
	<td> Cheque Number </td>
	<td> <input type="text" name="rchecquenumber"> </td>
</tr>
<tr>
	<td colspan=2> Create New Account  </td>
</tr>
<tr>	
	<td colspan=2>  <a href="CustomerMaster.jsp"> Customer </a>
		 			<a href="SupplierMaster.jsp"> Supplier </a> 
		 			<a href="GeneralLedger.jsp"> GeneralLedger </a>
	</td>
</tr>

</table>
<table align="center" id="receiptstable">
<tr>
	<td> Name of Account</td>
		
			 <%	
			 try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select ccode,cname from CustomerMaster"); %>
	<td> 
	  <select name="raccount" id="raccount" >
	  	<option> </option>
       		 <%  while(rs.next()){ %>
            		<option value="<%=rs.getString(1) %>" > <%=rs.getString(2)%> </option>
            		            		
        	<% } %>
  				
	 <% }
		catch(Exception e){} %>
	
		
	<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select scode,sname from SupplierMaster"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		 
        	<% } %>
 
	 <% }
		catch(Exception e){} %>
	
	 		<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select gcode,gname from GeneralLedger2"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		   
        	<% } %>
        </select>	
	</td>
	 <% }
		catch(Exception e){} %>
		<td> Amount </td>
	<td> <input type="text" name="ramountt"> </td>
</tr>

<tr>
	<td> <input type="button" value="add" onclick="addRow('receiptstable')" > </td>
	<td> <input type="button" value="remove" > </td>
</tr>	
	
<%--
<tr>
	<td> Name of Account </td>
	
			 <%	
			 try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select ccode,cname from CustomerMaster"); %>
	<td> 
	  <select name="raccount2" id="raccount2" >
	  		<option> </option>
       		 <%  while(rs.next()){ %>
            		<option value="<%=rs.getString(1) %>" > <%=rs.getString(2)%> </option>
            		            		
        	<% } %>
  				
	 <% }
		catch(Exception e){} %>
	
		
	<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select scode,sname from SupplierMaster"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		 
        	<% } %>
 
	 <% }
		catch(Exception e){} %>
	
	<%
			try
			{
			   st=con.createStatement() ;
       		   rs=st.executeQuery("select gcode,gname from GeneralLedger2"); %>
	 	
        	<%  while(rs.next()){ %>
         		   <option value="<%=rs.getString(1) %>"><%= rs.getString(2)%></option>
         		   
        	<% } %>
        </select>	
	</td>
	 <% }
		catch(Exception e){} %>
</tr>

<tr>
	<td colspan=2> Create New Account  </td>
</tr>
<tr>	
	<td colspan=2> <input type="radio" name="r1"> <a href="CustomerMaster.jsp"> Customer </a>
		 <input type="radio" name="r1"> <a href="SupplierMaster.jsp"> Supplier </a> 
		 <input type="radio" name="r1"> <a href="GeneralLedger.jsp"> GeneralLedger </a>
	</td>
</tr>

<tr>
	<td> Amount </td>
	<td> <input type="text" name="ramountt2"> </td>
</tr>
--%>
<tr>
	<td> Narration </td>
	<td> <input type="text" name="rnarration"> </td>
</tr>

<tr>
	<td> <input type="submit" value="Submit"> </td>

</table>
</form>
</body>
</html>